package com.unionpay.upyzt.spring.example.entity;

import com.unionpay.upyzt.Upyzt;
import com.unionpay.upyzt.exception.InvalidRequestException;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.HashMap;
import java.util.Map;

@Data
@AllArgsConstructor
@NoArgsConstructor
public class IdCard {
    /**
     * 上传身份证返回的参数
     */
    private String resourceLocation;
    private String resourceBackLocation;
    private String copy;
    private String national;
    private String number;
    private String name;
    private String startTime;
    private String endTime;

    public Map<String,Object> toMap(){
        Map<String, Object> idCard = new HashMap<>();
        idCard.put("copy", this.copy);
        idCard.put("national", this.national);
        try {
            idCard.put("number", Upyzt.encryptField(this.number));
            idCard.put("name", Upyzt.encryptField(this.name));
        } catch (InvalidRequestException e) {
            throw new RuntimeException(e);
        }
        idCard.put("valid_time", this.startTime+","+this.endTime);
        return idCard;
    }

}
